//init state
const state = () => ({
   param: [
    /*{
      comId: 1,
      serId: 1,
      serShowImgGroup: [
        "https://dsfs.oppo.com/archives/202107/testing_2021072710070160ff6e7da3098.png?_w_=2312&_h_=410&x-oss-process=image/format,webp",
        "https://dsfs.oppo.com/archives/202107/2021072111070760f7948399498.png?_w_=1125&_h_=411&x-oss-process=image/format,webp",
        "https://dsfs.oppo.com/archives/202105/2021052707050960af7dd541aab.png?_w_=2312&_h_=1098&x-oss-process=image/format,webp",
        "https://dsfs.oppo.com/archives/202105/2021052707052060af7de0e8a4d.png?_w_=2312&_h_=1862&x-oss-process=image/format,webp",
        "https://dsfs.oppo.com/archives/202105/2021052707052460af7de447c16.png?_w_=2312&_h_=1676&x-oss-process=image/format,webp",
        "https://dsfs.oppo.com/archives/202105/2021052707052760af7de7d80dd.png?_w_=2312&_h_=2140&x-oss-process=image/format,webp",
        "https://dsfs.oppo.com/archives/202105/2021052707053160af7deb61b72.png?_w_=2312&_h_=2140&x-oss-process=image/format,webp",
        "https://dsfs.oppo.com/archives/202105/2021052707053560af7def18cc5.png?_w_=2312&_h_=1546&x-oss-process=image/format,webp",
        "https://dsfs.oppo.com/archives/202105/2021052707051960af7e1b395dd.png?_w_=2312&_h_=2146&x-oss-process=image/format,webp",
        "https://dsfs.oppo.com/archives/202105/2021052707053160af7e27c4966.png?_w_=2312&_h_=3216&x-oss-process=image/format,webp",
        "https://dsfs.oppo.com/archives/202107/testing_2021070205070060dedf2c77eb0.png?_w_=1156&_h_=1334&x-oss-process=image/format,webp"
      ],
      content: {
        comShowMinImgGroup: [
          "https://dsfs.oppo.com/archives/202105/_thumbnail/thumbnail_2021051908054160a4ff5125789.png?_w_=160&amp;_h_=160",
          "https://dsfs.oppo.com/archives/202105/_thumbnail/thumbnail_2021052011051260a5da94a9324.png?_w_=160&amp;_h_=160",
          "https://dsfs.oppo.com/archives/202105/_thumbnail/thumbnail_2021051908054360a4ff5361d4c.png?_w_=160&amp;_h_=160",
          "https://dsfs.oppo.com/archives/202105/_thumbnail/thumbnail_2021051908054660a4ff5677dee.png?_w_=160&amp;_h_=160",
          "https://dsfs.oppo.com/archives/202105/_thumbnail/thumbnail_2021051908054960a4ff5916a44.png?_w_=160&amp;_h_=160",
          "https://dsfs.oppo.com/archives/202105/_thumbnail/thumbnail_2021051908055160a4ff5bb36ca.png?_w_=160&amp;_h_=160",
          "https://dsfs.oppo.com/archives/202105/_thumbnail/thumbnail_2021051908055460a4ff5e48e29.png?_w_=160&amp;_h_=160",
          "https://dsfs.oppo.com/archives/202105/_thumbnail/thumbnail_2021051908055660a4ff60d38d2.png?_w_=160&amp;_h_=160",
        ],
        comShowMaxImgGroup: [
          "https://dsfs.oppo.com/archives/202105/2021051908054160a4ff5125789.png?_w_=1080&amp;_h_=1080",
          "https://dsfs.oppo.com/archives/202105/2021052011051260a5da94a9324.png?_w_=1080&amp;_h_=1080",
          "https://dsfs.oppo.com/archives/202105/2021051908054360a4ff5361d4c.png?_w_=1080&amp;_h_=1080",
          "https://dsfs.oppo.com/archives/202105/2021051908054660a4ff5677dee.png?_w_=1080&amp;_h_=1080",
          "https://dsfs.oppo.com/archives/202105/2021051908054960a4ff5916a44.png?_w_=1080&amp;_h_=1080",
          "https://dsfs.oppo.com/archives/202105/2021051908055160a4ff5bb36ca.png?_w_=1080&amp;_h_=1080",
          "https://dsfs.oppo.com/archives/202105/2021051908055460a4ff5e48e29.png?_w_=1080&amp;_h_=1080",
          "https://dsfs.oppo.com/archives/202105/2021051908055660a4ff60d38d2.png?_w_=1080&amp;_h_=1080"
        ],
        currentSerName: "OPPO Reno6 5G",
        currentColor: "星河入梦",
        currentConfig: "12G+256G",
        currentService: "",
        description: [
          "①【专业影像】6400万水光人像镜头；",
          "②【超级闪充】65W超级闪充；",
          "③【5G芯片】天玑1200 5G芯片；",
          "③【变速高刷】90Hz高感曲面屏，无极稳帧。"
        ],
        comPrice: 3799,
        serColor: ["夜海", "夏日晴海", "星河入梦", "星黛紫", "测试颜色"],
        serConfig: ["8G+128G", "12G+256G"],
        serService: [
          "屏碎保一年 ￥249",
          "屏碎保+延长保 ￥250",
          "0享无忧 ￥258",
          "OPPO Care+ ￥469",
          "延长保半年 ￥79",
          "延长保一年 ￥129",
        ],
        currShowImg: "https://dsfs.oppo.com/archives/202105/2021051908054160a4ff5125789.png?_w_=1080&amp;_h_=1080"
      },
    },
    {
      comId: 2,
      serId: 1,
      serShowImgGroup: [
        "https://dsfs.oppo.com/archives/202107/testing_2021072710070160ff6e7da3098.png?_w_=2312&_h_=410&x-oss-process=image/format,webp",
        "https://dsfs.oppo.com/archives/202107/2021072111070760f7948399498.png?_w_=1125&_h_=411&x-oss-process=image/format,webp",
        "https://dsfs.oppo.com/archives/202105/2021052707050960af7dd541aab.png?_w_=2312&_h_=1098&x-oss-process=image/format,webp",
        "https://dsfs.oppo.com/archives/202105/2021052707052060af7de0e8a4d.png?_w_=2312&_h_=1862&x-oss-process=image/format,webp",
        "https://dsfs.oppo.com/archives/202105/2021052707052460af7de447c16.png?_w_=2312&_h_=1676&x-oss-process=image/format,webp",
        "https://dsfs.oppo.com/archives/202105/2021052707052760af7de7d80dd.png?_w_=2312&_h_=2140&x-oss-process=image/format,webp",
        "https://dsfs.oppo.com/archives/202105/2021052707053160af7deb61b72.png?_w_=2312&_h_=2140&x-oss-process=image/format,webp",
        "https://dsfs.oppo.com/archives/202105/2021052707053560af7def18cc5.png?_w_=2312&_h_=1546&x-oss-process=image/format,webp",
        "https://dsfs.oppo.com/archives/202105/2021052707051960af7e1b395dd.png?_w_=2312&_h_=2146&x-oss-process=image/format,webp",
        "https://dsfs.oppo.com/archives/202105/2021052707053160af7e27c4966.png?_w_=2312&_h_=3216&x-oss-process=image/format,webp",
        "https://dsfs.oppo.com/archives/202107/testing_2021070205070060dedf2c77eb0.png?_w_=1156&_h_=1334&x-oss-process=image/format,webp"
      ],
      content: {
        comShowMinImgGroup: [
          "https://dsfs.oppo.com/archives/202105/_thumbnail/thumbnail_2021051908054160a4ff5125789.png?_w_=160&amp;_h_=160",
          "https://dsfs.oppo.com/archives/202105/_thumbnail/thumbnail_2021052011051260a5da94a9324.png?_w_=160&amp;_h_=160",
          "https://dsfs.oppo.com/archives/202105/_thumbnail/thumbnail_2021051908054360a4ff5361d4c.png?_w_=160&amp;_h_=160",
          "https://dsfs.oppo.com/archives/202105/_thumbnail/thumbnail_2021051908054660a4ff5677dee.png?_w_=160&amp;_h_=160",
          "https://dsfs.oppo.com/archives/202105/_thumbnail/thumbnail_2021051908054960a4ff5916a44.png?_w_=160&amp;_h_=160",
          "https://dsfs.oppo.com/archives/202105/_thumbnail/thumbnail_2021051908055160a4ff5bb36ca.png?_w_=160&amp;_h_=160",
          "https://dsfs.oppo.com/archives/202105/_thumbnail/thumbnail_2021051908055460a4ff5e48e29.png?_w_=160&amp;_h_=160",
          "https://dsfs.oppo.com/archives/202105/_thumbnail/thumbnail_2021051908055660a4ff60d38d2.png?_w_=160&amp;_h_=160",
        ],
        comShowMaxImgGroup: [
          "https://dsfs.oppo.com/archives/202105/2021051908054160a4ff5125789.png?_w_=1080&amp;_h_=1080",
          "https://dsfs.oppo.com/archives/202105/2021052011051260a5da94a9324.png?_w_=1080&amp;_h_=1080",
          "https://dsfs.oppo.com/archives/202105/2021051908054360a4ff5361d4c.png?_w_=1080&amp;_h_=1080",
          "https://dsfs.oppo.com/archives/202105/2021051908054660a4ff5677dee.png?_w_=1080&amp;_h_=1080",
          "https://dsfs.oppo.com/archives/202105/2021051908054960a4ff5916a44.png?_w_=1080&amp;_h_=1080",
          "https://dsfs.oppo.com/archives/202105/2021051908055160a4ff5bb36ca.png?_w_=1080&amp;_h_=1080",
          "https://dsfs.oppo.com/archives/202105/2021051908055460a4ff5e48e29.png?_w_=1080&amp;_h_=1080",
          "https://dsfs.oppo.com/archives/202105/2021051908055660a4ff60d38d2.png?_w_=1080&amp;_h_=1080"
        ],
        currentSerName: "OPPO Reno6 5G",
        currentColor: "夜海",
        currentConfig: "12G+256G",
        currentService: "",
        description: [
          "①【专业影像】6400万水光人像镜头；",
          "②【超级闪充】65W超级闪充；",
          "③【5G芯片】天玑1200 5G芯片；",
          "③【变速高刷】90Hz高感曲面屏，无极稳帧。"
        ],
        comPrice: 3799,
        serColor: ["夜海", "夏日晴海", "星河入梦", "星黛紫", "测试颜色"],
        serConfig: ["8G+128G", "12G+256G"],
        serService: [
          "屏碎保一年 ￥249",
          "屏碎保+延长保 ￥250",
          "0享无忧 ￥258",
          "OPPO Care+ ￥469",
          "延长保半年 ￥79",
          "延长保一年 ￥129",
        ],
        currShowImg: "https://dsfs.oppo.com/archives/202105/2021051908054160a4ff5125789.png?_w_=1080&amp;_h_=1080"
      },
    },
     {
       comId: 3,
       serId: 1,
       serShowImgGroup: [
         "https://dsfs.oppo.com/archives/202107/testing_2021072710070160ff6e7da3098.png?_w_=2312&_h_=410&x-oss-process=image/format,webp",
         "https://dsfs.oppo.com/archives/202107/2021072111070760f7948399498.png?_w_=1125&_h_=411&x-oss-process=image/format,webp",
         "https://dsfs.oppo.com/archives/202105/2021052707050960af7dd541aab.png?_w_=2312&_h_=1098&x-oss-process=image/format,webp",
         "https://dsfs.oppo.com/archives/202105/2021052707052060af7de0e8a4d.png?_w_=2312&_h_=1862&x-oss-process=image/format,webp",
         "https://dsfs.oppo.com/archives/202105/2021052707052460af7de447c16.png?_w_=2312&_h_=1676&x-oss-process=image/format,webp",
         "https://dsfs.oppo.com/archives/202105/2021052707052760af7de7d80dd.png?_w_=2312&_h_=2140&x-oss-process=image/format,webp",
         "https://dsfs.oppo.com/archives/202105/2021052707053160af7deb61b72.png?_w_=2312&_h_=2140&x-oss-process=image/format,webp",
         "https://dsfs.oppo.com/archives/202105/2021052707053560af7def18cc5.png?_w_=2312&_h_=1546&x-oss-process=image/format,webp",
         "https://dsfs.oppo.com/archives/202105/2021052707051960af7e1b395dd.png?_w_=2312&_h_=2146&x-oss-process=image/format,webp",
         "https://dsfs.oppo.com/archives/202105/2021052707053160af7e27c4966.png?_w_=2312&_h_=3216&x-oss-process=image/format,webp",
         "https://dsfs.oppo.com/archives/202107/testing_2021070205070060dedf2c77eb0.png?_w_=1156&_h_=1334&x-oss-process=image/format,webp"
       ],
       content: {
         comShowMinImgGroup: [
           "https://dsfs.oppo.com/archives/202105/_thumbnail/thumbnail_2021051908054160a4ff5125789.png?_w_=160&amp;_h_=160",
           "https://dsfs.oppo.com/archives/202105/_thumbnail/thumbnail_2021052011051260a5da94a9324.png?_w_=160&amp;_h_=160",
           "https://dsfs.oppo.com/archives/202105/_thumbnail/thumbnail_2021051908054360a4ff5361d4c.png?_w_=160&amp;_h_=160",
           "https://dsfs.oppo.com/archives/202105/_thumbnail/thumbnail_2021051908054660a4ff5677dee.png?_w_=160&amp;_h_=160",
           "https://dsfs.oppo.com/archives/202105/_thumbnail/thumbnail_2021051908054960a4ff5916a44.png?_w_=160&amp;_h_=160",
           "https://dsfs.oppo.com/archives/202105/_thumbnail/thumbnail_2021051908055160a4ff5bb36ca.png?_w_=160&amp;_h_=160",
           "https://dsfs.oppo.com/archives/202105/_thumbnail/thumbnail_2021051908055460a4ff5e48e29.png?_w_=160&amp;_h_=160",
           "https://dsfs.oppo.com/archives/202105/_thumbnail/thumbnail_2021051908055660a4ff60d38d2.png?_w_=160&amp;_h_=160",
         ],
         comShowMaxImgGroup: [
           "https://dsfs.oppo.com/archives/202105/2021051908054160a4ff5125789.png?_w_=1080&amp;_h_=1080",
           "https://dsfs.oppo.com/archives/202105/2021052011051260a5da94a9324.png?_w_=1080&amp;_h_=1080",
           "https://dsfs.oppo.com/archives/202105/2021051908054360a4ff5361d4c.png?_w_=1080&amp;_h_=1080",
           "https://dsfs.oppo.com/archives/202105/2021051908054660a4ff5677dee.png?_w_=1080&amp;_h_=1080",
           "https://dsfs.oppo.com/archives/202105/2021051908054960a4ff5916a44.png?_w_=1080&amp;_h_=1080",
           "https://dsfs.oppo.com/archives/202105/2021051908055160a4ff5bb36ca.png?_w_=1080&amp;_h_=1080",
           "https://dsfs.oppo.com/archives/202105/2021051908055460a4ff5e48e29.png?_w_=1080&amp;_h_=1080",
           "https://dsfs.oppo.com/archives/202105/2021051908055660a4ff60d38d2.png?_w_=1080&amp;_h_=1080"
         ],
         currentSerName: "OPPO Reno6 5G",
         currentColor: "星河入梦",
         currentConfig: "8G+128G",
         currentService: "",
         description: [
           "①【专业影像】6400万水光人像镜头；",
           "②【超级闪充】65W超级闪充；",
           "③【5G芯片】天玑1200 5G芯片；",
           "③【变速高刷】90Hz高感曲面屏，无极稳帧。"
         ],
         comPrice: 3799,
         serColor: ["夜海", "夏日晴海", "星河入梦", "星黛紫", "测试颜色"],
         serConfig: ["8G+128G", "12G+256G"],
         serService: [
           "屏碎保一年 ￥249",
           "屏碎保+延长保 ￥250",
           "0享无忧 ￥258",
           "OPPO Care+ ￥469",
           "延长保半年 ￥79",
           "延长保一年 ￥129",
         ],
         currShowImg: "https://dsfs.oppo.com/archives/202105/2021051908054160a4ff5125789.png?_w_=1080&amp;_h_=1080"
       },
     },
     {
       comId: 4,
       serId: 1,
       serShowImgGroup: [
         "https://dsfs.oppo.com/archives/202107/testing_2021072710070160ff6e7da3098.png?_w_=2312&_h_=410&x-oss-process=image/format,webp",
         "https://dsfs.oppo.com/archives/202107/2021072111070760f7948399498.png?_w_=1125&_h_=411&x-oss-process=image/format,webp",
         "https://dsfs.oppo.com/archives/202105/2021052707050960af7dd541aab.png?_w_=2312&_h_=1098&x-oss-process=image/format,webp",
         "https://dsfs.oppo.com/archives/202105/2021052707052060af7de0e8a4d.png?_w_=2312&_h_=1862&x-oss-process=image/format,webp",
         "https://dsfs.oppo.com/archives/202105/2021052707052460af7de447c16.png?_w_=2312&_h_=1676&x-oss-process=image/format,webp",
         "https://dsfs.oppo.com/archives/202105/2021052707052760af7de7d80dd.png?_w_=2312&_h_=2140&x-oss-process=image/format,webp",
         "https://dsfs.oppo.com/archives/202105/2021052707053160af7deb61b72.png?_w_=2312&_h_=2140&x-oss-process=image/format,webp",
         "https://dsfs.oppo.com/archives/202105/2021052707053560af7def18cc5.png?_w_=2312&_h_=1546&x-oss-process=image/format,webp",
         "https://dsfs.oppo.com/archives/202105/2021052707051960af7e1b395dd.png?_w_=2312&_h_=2146&x-oss-process=image/format,webp",
         "https://dsfs.oppo.com/archives/202105/2021052707053160af7e27c4966.png?_w_=2312&_h_=3216&x-oss-process=image/format,webp",
         "https://dsfs.oppo.com/archives/202107/testing_2021070205070060dedf2c77eb0.png?_w_=1156&_h_=1334&x-oss-process=image/format,webp"
       ],
       content: {
         comShowMinImgGroup: [
           "https://dsfs.oppo.com/archives/202105/_thumbnail/thumbnail_2021051908054160a4ff5125789.png?_w_=160&amp;_h_=160",
           "https://dsfs.oppo.com/archives/202105/_thumbnail/thumbnail_2021052011051260a5da94a9324.png?_w_=160&amp;_h_=160",
           "https://dsfs.oppo.com/archives/202105/_thumbnail/thumbnail_2021051908054360a4ff5361d4c.png?_w_=160&amp;_h_=160",
           "https://dsfs.oppo.com/archives/202105/_thumbnail/thumbnail_2021051908054660a4ff5677dee.png?_w_=160&amp;_h_=160",
           "https://dsfs.oppo.com/archives/202105/_thumbnail/thumbnail_2021051908054960a4ff5916a44.png?_w_=160&amp;_h_=160",
           "https://dsfs.oppo.com/archives/202105/_thumbnail/thumbnail_2021051908055160a4ff5bb36ca.png?_w_=160&amp;_h_=160",
           "https://dsfs.oppo.com/archives/202105/_thumbnail/thumbnail_2021051908055460a4ff5e48e29.png?_w_=160&amp;_h_=160",
           "https://dsfs.oppo.com/archives/202105/_thumbnail/thumbnail_2021051908055660a4ff60d38d2.png?_w_=160&amp;_h_=160",
         ],
         comShowMaxImgGroup: [
           "https://dsfs.oppo.com/archives/202105/2021051908054160a4ff5125789.png?_w_=1080&amp;_h_=1080",
           "https://dsfs.oppo.com/archives/202105/2021052011051260a5da94a9324.png?_w_=1080&amp;_h_=1080",
           "https://dsfs.oppo.com/archives/202105/2021051908054360a4ff5361d4c.png?_w_=1080&amp;_h_=1080",
           "https://dsfs.oppo.com/archives/202105/2021051908054660a4ff5677dee.png?_w_=1080&amp;_h_=1080",
           "https://dsfs.oppo.com/archives/202105/2021051908054960a4ff5916a44.png?_w_=1080&amp;_h_=1080",
           "https://dsfs.oppo.com/archives/202105/2021051908055160a4ff5bb36ca.png?_w_=1080&amp;_h_=1080",
           "https://dsfs.oppo.com/archives/202105/2021051908055460a4ff5e48e29.png?_w_=1080&amp;_h_=1080",
           "https://dsfs.oppo.com/archives/202105/2021051908055660a4ff60d38d2.png?_w_=1080&amp;_h_=1080"
         ],
         currentSerName: "OPPO Reno6 5G",
         currentColor: "夜海",
         currentConfig: "8G+128G",
         currentService: "",
         description: [
           "①【专业影像】6400万水光人像镜头；",
           "②【超级闪充】65W超级闪充；",
           "③【5G芯片】天玑1200 5G芯片；",
           "③【变速高刷】90Hz高感曲面屏，无极稳帧。"
         ],
         comPrice: 3799,
         serColor: ["夜海", "夏日晴海", "星河入梦", "星黛紫", "测试颜色"],
         serConfig: ["8G+128G", "12G+256G"],
         serService: [
           "屏碎保一年 ￥249",
           "屏碎保+延长保 ￥250",
           "0享无忧 ￥258",
           "OPPO Care+ ￥469",
           "延长保半年 ￥79",
           "延长保一年 ￥129",
         ],
         currShowImg: "https://dsfs.oppo.com/archives/202105/2021051908054160a4ff5125789.png?_w_=1080&amp;_h_=1080"
       },
     }*/
  ]

})

//getters
const getters = {
  getAllData(state){
    return state;
  },
  getData(state){
    return state.param;
  },
  getComIdByManyConfigMsg(state){
    return function (configMsg) {
      //过滤条件：按序列编号、按颜色、按配置--》得出商品编号
      let element = state.param.filter(item => item.serId ==configMsg.serId && item.content.currentColor == configMsg.currColor && item.content.currentConfig == configMsg.currMomConfig)[0];
      if (configMsg.serviceName) {//如果传过来服务名的话，就修改服务名
        this.$store.dispatch("DetailData/updateCurrSerName",{comId: element.comId,currSerName: configMsg.serviceName});
      }
      this.$router.push({path: "/detail",query: { comId: element.comId,hash: configMsg.serviceName }})
    }
  },
  getComImgAndComPrice(state){//通过商品编号取得多条数据
    return function (comId) {
      let element = state.param.filter(item => {
        return item.comId == comId;
      })[0];
      let tempVal = {
        comShowMaxImgGroup: element.content.comShowMaxImgGroup[0],
        currentSerName: element.content.currentSerName,
        currentColor: element.content.currentColor,
        comPrice: element.content.comPrice,
        currentConfig: element.content.currentConfig
      }
      return tempVal;
    }
  },
  refreshDetailDataSessionStorageData(state){
    sessionStorage.setItem("DetailData",JSON.stringify(state.param))
  }
}

//actions
const actions = {
  updateCurrSerName({commit},{comId,currSerName}){//修改当前服务名
    commit("updateCurrSerName",{comId,currSerName})
  },
  addData({commit},payload){//向数组中添加数据
    return new Promise(resolve => {
      commit("addDataMut",payload);
      resolve(true);
    });
  },
  loadDataForDetailData({commit},payload){//将request的数据加载到store当中
    commit("loadDataForDetailDataMut",payload)
  },
  addDataForDetailDataBySessionStorage({commit}){//对store添加数据，从session当中取出数据添加
    commit("addDataForDetailDataBySessionStorageMut")
  }
}

//mutations
const mutations = {
  updateCurrSerName(state,{comId,currSerName}){
    let item = state.param.find(item => item.comId == comId);
    if (currSerName == item.content.currentService) item.content.currentService = "";
    else item.content.currentService = currSerName;
  },
  addDataMut(state,val){//向数组中添加数据
    state.param = [...state.param,...val];
  },
  loadDataForDetailDataMut(state,val){//将request的数据加载到store当中
    state.param = [...val];
  },
  addDataForDetailDataBySessionStorageMut(state){//对store添加数据，从session当中取出数据添加
    state.param = [...JSON.parse(sessionStorage.getItem("DetailData"))];
  }
}

export default {
  namespaced: true,
  state,
  getters,
  actions,
  mutations
}
